package com.fix.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fix.util.IOHelper;

public class FixConfig {
	/**
	 * Logger for this class
	 */
	private static final Log LOGGER = LogFactory.getLog(FixConfig.class);
	

	public static String defaultConfigFile = "/conf/fix/fix.conf";
	private Properties properties = null;

	private int connectionTimeOut;
	private boolean debugMode = false;

	public FixConfig() throws Exception {
		this(defaultConfigFile);
	}

	public FixConfig(String configFile) throws Exception {
		properties = new Properties();
		InputStream istream = null;
		try {
			istream = FixConfig.class.getResourceAsStream(configFile);
			LOGGER.debug("Cargando Configuracion ADCConfig: " + istream);
			properties.load(istream);
			initializeParameters();
		} catch (IOException e) {
			throw new Exception(e);
		} finally {
			IOHelper.closeInputStreams(istream);
		}
	}

	private void initializeParameters() {
		this.connectionTimeOut = Integer.parseInt(properties
				.getProperty("connectionTimeOut"));
		this.debugMode = "true".equalsIgnoreCase(properties
				.getProperty("debugMode"));
	}

	public int getConnectionTimeOut() {
		return connectionTimeOut;
	}

	public void setConnectionTimeOut(int connectionTimeOut) {
		this.connectionTimeOut = connectionTimeOut;
	}

	public boolean isDebugMode() {
		return debugMode;
	}

	public void setDebugMode(boolean debugMode) {
		this.debugMode = debugMode;
	}

}
